<?php
namespace Index\Controller;
use Think\Controller;
use Index\Controller\CommonController;
class QuestionController extends CommonController {
    public function indexAction(){

    	$qid  = I('get.qid');
    	$sql  = "select * from question where id='{$qid}'";
    	$data = M()->query($sql);

        $sql  = "select * from answer where qid='{$qid}'";
        $answers = M()->query($sql);
    	$this->assign('data',current($data));
        $this->assign('answers',$answers);
       	$this->display();
    }

    public function howtoaskAction()
    {
    	$this->display();
    }

    public function askAction(){
    	layout(false);
    	$this->display();
    }

    public function addAction()
    {
    	$data['content'] = I('post.editorValue','');
    	$data['title'] = I('post.title','');
    	$data['uid'] = $_SESSION['id'];
    	$data['create_time']=time();

    	$insertId = M('question')->add($data);


    	$cids = I('post.cid','');

    	foreach ($cids as $row) {
    		$insertData['qid'] = $insertId;
    		$insertData['cid'] = $row;
    		M('question_category')->add($insertData);
    	}

    	$this->success('发布成功',U('index/question/index',array('qid'=>$insertId)));
    }

    public function ueditorAction(){
        $data = new \Org\Util\Ueditor();
        echo $data->output();
    }
}

